package com.ruoyi.pims.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pims.domain.RyAbcCriteria;
import com.ruoyi.pims.service.IRyAbcCriteriaService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * ABC分类标准Controller
 * 
 * @author ruoyi
 * @date 2025-06-18
 */
@Controller
@RequestMapping("/pims/criteria")
public class RyAbcCriteriaController extends BaseController
{
    private String prefix = "pims/criteria";

    @Autowired
    private IRyAbcCriteriaService ryAbcCriteriaService;

    @RequiresPermissions("pims:criteria:view")
    @GetMapping()
    public String criteria()
    {
        return prefix + "/criteria";
    }

    /**
     * 查询ABC分类标准列表
     */
    @RequiresPermissions("pims:criteria:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RyAbcCriteria ryAbcCriteria)
    {
        startPage();
        List<RyAbcCriteria> list = ryAbcCriteriaService.selectRyAbcCriteriaList(ryAbcCriteria);
        return getDataTable(list);
    }

    /**
     * 导出ABC分类标准列表
     */
    @RequiresPermissions("pims:criteria:export")
    @Log(title = "ABC分类标准", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RyAbcCriteria ryAbcCriteria)
    {
        List<RyAbcCriteria> list = ryAbcCriteriaService.selectRyAbcCriteriaList(ryAbcCriteria);
        ExcelUtil<RyAbcCriteria> util = new ExcelUtil<RyAbcCriteria>(RyAbcCriteria.class);
        return util.exportExcel(list, "ABC分类标准数据");
    }

    /**
     * 新增ABC分类标准
     */
    @RequiresPermissions("pims:criteria:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存ABC分类标准
     */
    @RequiresPermissions("pims:criteria:add")
    @Log(title = "ABC分类标准", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RyAbcCriteria ryAbcCriteria)
    {
        return toAjax(ryAbcCriteriaService.insertRyAbcCriteria(ryAbcCriteria));
    }

    /**
     * 修改ABC分类标准
     */
    @RequiresPermissions("pims:criteria:edit")
    @GetMapping("/edit/{criteriaId}")
    public String edit(@PathVariable("criteriaId") Long criteriaId, ModelMap mmap)
    {
        RyAbcCriteria ryAbcCriteria = ryAbcCriteriaService.selectRyAbcCriteriaByCriteriaId(criteriaId);
        mmap.put("ryAbcCriteria", ryAbcCriteria);
        return prefix + "/edit";
    }

    /**
     * 修改保存ABC分类标准
     */
    @RequiresPermissions("pims:criteria:edit")
    @Log(title = "ABC分类标准", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RyAbcCriteria ryAbcCriteria)
    {
        return toAjax(ryAbcCriteriaService.updateRyAbcCriteria(ryAbcCriteria));
    }

    /**
     * 删除ABC分类标准
     */
    @RequiresPermissions("pims:criteria:remove")
    @Log(title = "ABC分类标准", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ryAbcCriteriaService.deleteRyAbcCriteriaByCriteriaIds(ids));
    }
}
